package bairui.international.model.status;

/**
 *
 * (抽奖状态)State_Prize
 */
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@com.lianjing.sh.model.common.annotation.Comment("抽奖状态")
@com.lianjing.sh.processing.info.annotation.InfoComment("抽奖状态")
public enum State_Prize implements com.sh_lianjing.state.Statable, com.sh_lianjing.standard.EnumCommentable<State_Prize> {

	/**
	 * <b>状态:</b> </br>
	 * (已上架)Uped</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已上架")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已上架")
	Uped("已上架")
,
	/**
	 * <b>状态:</b> </br>
	 * (已下架)Downed</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("已下架")
	@com.lianjing.sh.processing.info.annotation.InfoComment("已下架")
	Downed("已下架")
,
	/**
	 * <b>状态:</b> </br>
	 * (草稿)Draft</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("草稿")
	@com.lianjing.sh.processing.info.annotation.InfoComment("草稿")
	Draft("草稿")
,
	/**
	 * <b>状态:</b> </br>
	 * (完成)Finished</br>
	 */
	@com.lianjing.sh.model.common.annotation.Comment("完成")
	@com.lianjing.sh.processing.info.annotation.InfoComment("完成")
	Finished("完成")
;

	private static java.util.Map<String, State_Prize> Cache = new java.util.HashMap<>();
	static{
		for(State_Prize enumItem : State_Prize.values()){
			Cache.put(enumItem.getComment(), enumItem);
		}
	}

	private String comment;

	private State_Prize(String comment){
		this.comment = comment;
	}

	@Override
	public String toString() {
		return comment;
	}

	@Override
	public String getComment() {
		return comment;
	}

	/**
	 * 通过备注解析状态相关
	 */
	@Override
	public State_Prize parseByComment(String comment) {
		return State_Prize.parse(comment);
	}

	public static State_Prize parse(String comment) {
		State_Prize enumItem = Cache.get(comment);
		if(null == enumItem){
			 throw new com.sh_lianjing.standard.exception.EnumCommentableException(State_Prize.class, comment);
		}
		return enumItem;
	}

	/**
	 * from 转换方法相关
	 */
	/** <b>上架(已下架状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_up_from_Downed() throws com.sh_lianjing.state.StateConvertException {
		if(this != Downed){
			throw new com.sh_lianjing.state.StateConvertException(this, Uped);
		}
		return new com.sh_lianjing.state.StateTransition<State_Prize>("上架", this, Uped);
	}

	/** <b>完成(已下架状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_finished_from_Downed() throws com.sh_lianjing.state.StateConvertException {
		if(this != Downed){
			throw new com.sh_lianjing.state.StateConvertException(this, Finished);
		}
		return new com.sh_lianjing.state.StateTransition<State_Prize>("完成", this, Finished);
	}

	/** <b>下架(已上架状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_down_from_Uped() throws com.sh_lianjing.state.StateConvertException {
		if(this != Uped){
			throw new com.sh_lianjing.state.StateConvertException(this, Downed);
		}
		return new com.sh_lianjing.state.StateTransition<State_Prize>("下架", this, Downed);
	}

	/** <b>完成(已上架状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_finished_from_Uped() throws com.sh_lianjing.state.StateConvertException {
		if(this != Uped){
			throw new com.sh_lianjing.state.StateConvertException(this, Finished);
		}
		return new com.sh_lianjing.state.StateTransition<State_Prize>("完成", this, Finished);
	}

	/** <b>创建</b> */
	public static com.sh_lianjing.state.StateTransition<State_Prize> t_create() {
		return new com.sh_lianjing.state.StateTransition<State_Prize>("创建", null, Draft);
	}

	/** <b>发布(草稿状态)</b> */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_publish_from_Draft() throws com.sh_lianjing.state.StateConvertException {
		if(this != Draft){
			throw new com.sh_lianjing.state.StateConvertException(this, Uped);
		}
		return new com.sh_lianjing.state.StateTransition<State_Prize>("发布", this, Uped);
	}

	/**
	 * to 转换方法相关
	 */
	public com.sh_lianjing.state.StateTransition<State_Prize> t_finished_to_Finished() throws com.sh_lianjing.state.StateConvertException {
		if(this == Uped){
			return t_finished_from_Uped();
		}else if(this == Downed){
			return t_finished_from_Downed();
		}else{
			throw new com.sh_lianjing.state.StateConvertException(this, Finished);
		}
	}


	/**
	 * 验证方法相关
	 */
	public Validator validator(){
		return new Validator();
	}
	
	public class Validator {
		private com.sh_lianjing.state.validate.StateCondition<State_Prize> condition = new com.sh_lianjing.state.validate.StateCondition<>();
	
		public State_Prize end() throws com.sh_lianjing.state.StateException{
			if(!condition.validate(State_Prize.this)){
				throw new com.sh_lianjing.state.StateException("抽奖状态错误，不能执行操作");
			}
			return State_Prize.this;
		}
	
		/** <b>验证[已上架]状态</b> */
		public Validator v_Uped() {
			this.condition.add(Uped);
			return this;
		}
		/** <b>验证[已下架]状态</b> */
		public Validator v_Downed() {
			this.condition.add(Downed);
			return this;
		}
		/** <b>验证[草稿]状态</b> */
		public Validator v_Draft() {
			this.condition.add(Draft);
			return this;
		}
		/** <b>验证[完成]状态</b> */
		public Validator v_Finished() {
			this.condition.add(Finished);
			return this;
		}
	}

}
